package com.qianyucc.blog.controller.comm;

import com.qianyucc.blog.model.dto.*;
import com.qianyucc.blog.model.vo.*;
import com.qianyucc.blog.service.*;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.validation.annotation.*;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * @author lijing
 * @date 2019-10-13 12:19
 * @description 与评论相关的api
 */
@RestController("commCommentController")
@RequestMapping("comm/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @ApiOperation("提交评论")
    @PostMapping("/")
    public ResultVO comment(@RequestBody @Validated CommentDTO commentDTO) {
        commentService.insComment(commentDTO);
        return ResultVO.ok("评论成功！");
    }

    @ApiOperation("根据文章id获取该文章下所有评论")
    @GetMapping("/{id}")
    public List<CommentVO> getAllComments(@PathVariable String id) {
        List<CommentVO> comments = commentService.findCommentByArticleId(id);
        return comments;
    }
}
